<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Redis;

class Goodssale extends Model
{
	//商品促销表
    protected $table = 'shop_goods_sales';

    public function goods()
    {
    	return $this->hasOne('App\Model\Goods', 'id','goods_id');
    }

    public static function hasSale()
    {
      $saleKey = 'goods_sale_set_data';
      $saleHashArr = Redis::sMembers($saleKey);

      $saleArr = [];

      foreach ($saleHashArr as $k => $v) {

          $saleArr[$k]['start_time'] = Redis::hGet($v, 'start_time');
          $saleArr[$k]['end_time'] = Redis::hGet($v, 'end_time');

      }

      foreach($saleArr as $v) {

        if($v['start_time'] < date('Y-m-d H:i:s') && $v['end_time'] > date('Y-m-d H:i:s')) {
            return true;
        }
      }
      return false;

    }

}
